package com.yty.myadmin.controler;

import com.yty.myadmin.dao.UserRoleDAO;
import com.yty.myadmin.domain.UserRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

@Controller
public class Tables {


    @Autowired
    private UserRoleDAO userRoleDAO;
    @RequestMapping("/jqgrid")
    public String getJqgrid(){

        return "jqgrid";
    }

    @RequestMapping("/tables/{name}")
    public String Tables(
            @PathVariable String name, Model model
    ){
        System.out.println(name);
        return "tables";
    }
    @RequestMapping(value = "/tables",method = RequestMethod.GET)
    public String getTables(
            @RequestParam(value = "name",required = false) String name, Model model
    ){
        model.addAttribute("name",name);
        List<UserRole> userRoles;
        userRoles = userRoleDAO.findAllExceptName(name);
        for(UserRole userRole:userRoles){
            System.out.println(userRole.getUserId());
            System.out.println(userRole.getName());
            System.out.println(userRole.getRoles());
        };
        model.addAttribute("userRoles",userRoles);
        return "tables";
    }


}
